<template>
	<view class="content">
        <uni-password :show="true" digits="6" @confirm="onConfirm">
        	请输入支付密码
        </uni-password>
		<view class="g-frame-mask" v-if="showPopup"></view>
		<view class="g-frame" v-if="showPopup">
			<view class="m-frame-header">
			    <view class="u-frame-title">提示</view>
			    <image class="u-frame-close" src="../../../static/icons/ydt/close.png" mode="widthFix" @tap="togglePopup"></image>
			</view>
			<view class="u-frame-cont" v-if="onloadData.pageType =='zbturn'">本次转出{{onloadData.zbamount}}珠宝粮仓，请确认</view>
			<view class="u-frame-cont" v-if="onloadData.pageType =='mammon'">本次领取珠宝流量:{{onloadData.makerAmount}}，请确认</view>
			<view class="u-frame-cont" v-if="onloadData.pageType =='takecash'">本次退取{{onloadData.price}}珠宝粮仓，请确认</view>
			<view class="m-frame-footer">
			    <view class="u-reset" @tap="togglePopup">取消</view>
			    <view class="u-confirm" @tap="toConfirm">确定</view>
			</view>
		</view>
		<view class="m-full-loading" v-if="showloading">
			<view class="m-loading">
				<image src="../../../static/images/loading.gif" mode="widthFix"></image>
			    <text>加载中</text>
			</view>
		</view>
	</view>
</template>

<script>
	import henglang from '@/common/common_zb.js'
	import md5 from '@/common/md5.js'
	export default {
		
		data() {
			return {
				//提现
				sendData:{
					amount:'',
					method:'',
					account:'',
					paypwd: '',
					code:''
				},
				showloading: false,
				showPopup: false,
				password: '',
				onloadData:{}
			}
		},
		methods: {
			togglePopup() {
			    this.showPopup = !this.showPopup;
			},
			onConfirm(e) {
				this.showPopup = true;
				this.password = md5(e);
			},
			toConfirm() {
				let that = this;
				that.showPopup = false;
				that.showloading = true;
				switch (that.onloadData.pageType){
					case 'takecash':
						setTimeout(() => {
							that.postData()
						}, 500)
						break;
					case 'zbturn':
						setTimeout(() => {
							that.postZbData()
						}, 500)
						break;
					case 'mammon':
						setTimeout(() => {
							that.postMamData()
						}, 500)
						break;
					default:
						break;
				}
			},
			//提交提现数据
			postData() {
				let that = this
				that.sendData.paypwd = that.password;
				henglang.post('withdraw/applyWithdraw',that.sendData,true,function(res){
					that.showloading = false;
					if(res.data.code == 0){
						henglang.showToast(res.data.msg,500);
						setTimeout(() => {
							uni.redirectTo({
								url:'/pages/user/hl_takedeital'
							})
						}, 500)
					}else if(res.data.code == -2){
						henglang.showToast(res.data.msg);
						setTimeout(() => {
							uni.navigateBack()
						}, 3000)
					}else{
						henglang.showToast(res.data.msg);
					}
				});
			},
			
			postZbData() {
				let that = this
				henglang.post('Transfer/jewelTurnOut',{amount:Number(that.onloadData.zbamount),paypwd:that.password},true,function(res){
					
					that.showloading = false;
					if(res.data.code == 0){
						henglang.showToast(res.data.msg,500);
						setTimeout(() => {
							uni.redirectTo({
								url:'/pages/jewel/order/bill?type=2'
							})
						}, 500)
					}else{
						henglang.showToast(res.data.msg);
					}
				},function(res){
					henglang.showToast('请求失败');
					return;
				});
			},
			postMamData() {
				let that = this
				henglang.post('Maker/apply',{money:Number(that.onloadData.makerAmount),paypwd:that.password},true,function(res){
					
					that.showloading = false;
					if(res.data.code == 0){
						henglang.showToast(res.data.msg,500);
						setTimeout(() => {
							uni.redirectTo({
								url:'/pages/jewel/user/mammon_deital'
							})
						}, 500)
					}else{
						henglang.showToast(res.data.msg);
					}
				},function(res){
					henglang.showToast('请求失败');
					return;
				});
			},
			//返回上一页带参数
			// backSetData(val,val2) {
			// 	var pages = getCurrentPages();
			// 	var currPage = pages[pages.length - 1]; //当前页面
			// 	var prevPage = pages[pages.length - 2]; //上一个页面
			// 	//直接调用上一个页面的setData()方法，把数据存到上一个页面中去
			// 	prevPage.setData({
			// 	    isTransOk:val,
			// 		in_money:val2
			// 	})
			// 	uni.navigateBack();
			// }
		},
		onLoad(option) {
			let that = this
			that.onloadData = option
			that.sendData = {
				amount:option.amount,
				method:option.method,
				account:option.account,
				code:option.code
			}
		}
	}
</script>
<style>
	.content {
		text-align: center;
		height: 400upx;
	}
	.m-full-loading{
		background-color: transparent;
	}
	.m-loading{
		z-index: 21;
	}
	.g-frame {
	    width: 581upx;
	    background: #fff;
	    border-radius: 20upx;
	    position: fixed;
	    top: 50%;
	    overflow: hidden;
	    left: 50%;
		margin-top: -215upx;
		margin-left: -290upx;
		z-index: 12;
	}
	
	.g-frame-mask {
	    background: #000;
	    opacity: .5;
	    height: 100vh;
	    width: 100%;
	    position: fixed;
	    top: 0upx;
		z-index: 11;
	}
	
	.m-frame-header {
	    height: 110upx;
	    width: 100%;
	    background: #d71311;
	    border-top-right-radius: 20upx;
	    border-top-left-radius: 20upx;
		position: relative;
		margin-bottom: 35upx;
	}
	.u-frame-title {
	    width: 100%;
	    text-align: center;
	    color: #fff;
	    line-height: 110upx;
	    font-size: 32upx;
	}
	
	.u-frame-close {
	    width: 42upx;
	    height: 42upx;
	    background-size: 100%;
	    position: absolute;
	    top: 50%;
		margin-top: -21upx;
	    right: 32upx;
	}
	.u-frame-cont{
		text-align: center;
		font-size: 36upx;
		padding-bottom: 35upx;
		line-height: 60upx;
		width: 500upx;
		margin: 0 auto;
	}
	.m-frame-footer {
	    height: 100upx;
	    width: 100%;
	    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
		display: flex;
		align-items: center;
		margin-top: 20upx;
	}
	
	.m-frame-footer view {
		flex: 1;
	    line-height: 100upx;
	    text-align: center;
	    font-size: 32upx;
	}
	
	.u-reset {
	    color: #ff0000;
	    background: #fff;
	}
	
	.u-confirm {
	    background: #d71311;
	    color: #fff;
	    border-bottom-right-radius: 16upx;
	}
	
</style>
